<%@page import="java.io.File"%>
<%@page import="models.BeanComments"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%
if(request.getAttribute("beanComments") != null){
BeanComments beanComments= (BeanComments)request.getAttribute("beanComments");%>
<div id="divShowComments<%=beanComments.getTweet().getId() %>"> 
</br>
<a style="margin-top:1em" class="showComments" data-idtweet="<%=beanComments.getTweet().getId() %>" href="javascript:void(0);"><%=beanComments.getComments().size() %> comments!</a> 
</div>
<div style="display:none" id="comments<%=beanComments.getTweet().getId()%>">
<% if(beanComments.getComments().size()>0) { %>
<table class="commentsTable">
<% for(int i = 0; i < beanComments.getComments().size(); i++) { %>
<tr><td class="tdComment" >
Por <a href="HomeController?viewUser=<%=beanComments.getComments().get(i).getUser()%>"><%=beanComments.getComments().get(i).getUser()%></a> en <%=beanComments.getComments().get(i).getTimestamp().toString()%>  <% if(beanComments.getComments().get(i).getUser().equals(session.getAttribute("user")) || session.getAttribute("isAdmin") != null) {%>|  <a class="deleteComment" data-commentuser="<%=beanComments.getComments().get(i).getUser()%>" data-idcomment="<%=beanComments.getComments().get(i).getIdComment()%>" data-idtweet="<%=beanComments.getComments().get(i).getIdTweet()%>" href="javascript:void(0);">Eliminar</a><% } %>
<div style="margin-left:20px; background-color:white;">
<div class="tweetImg">
<% 
String path = getServletContext().getRealPath("/etc/img");
File f = new java.io.File(path + "/tweet_" + beanComments.getComments().get(i).getUser() + ".jpg");
if(f.exists()) {%><img  src="./etc/img/tweet_<%=beanComments.getComments().get(i).getUser()%>.jpg"/>
<%} else{ %><img src="./etc/img/tweet_nopic.jpg"/>
<%} %></div>
<div class="commentDiv"><p><%=  beanComments.getComments().get(i).getComment() %></p></div>
</div>
</td></tr>
<% } %>
</table>
<% } %>
<%if(beanComments.getTweet().isAllowComments()){ %>
<div class="divComment" id="divComment<%=beanComments.getTweet().getId() %>"> 
	<form  id="commentForm<%=beanComments.getTweet().getId() %>" action="" method="POST">
		<TEXTAREA class="comment-textarea" name="comment" id="comment" class="required" maxlength="200"/></TEXTAREA>
		<input type=hidden name="tweetId" value="<%=beanComments.getTweet().getId() %>">
		<input type=hidden name="newComment" value="true">
		</br>
		<button type="button" data-id="<%=beanComments.getTweet().getId() %>" class="submitComment" style="padding:5px; margin:10px;">Enviar comentario</button>
		<button type=reset class="cancelComment" data-idtweet="<%=beanComments.getTweet().getId() %>" onclick="javascript:void(0);" style="padding:5px; margin:10px;">Cancel</button>
	</form>
</div>
<%}%>
</br>
<a style="margin-top:1em" class="hideComments"  data-idtweet="<%=beanComments.getTweet().getId()%>" href="javascript:void(0);">Esconder comentarios.</a>
 </div>
 <%}%>
</body>
</html>